<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input v-model="listQuery.deviceId" clearable class="filter-item" style="width: 200px;" placeholder="搜索设备Id" />
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      size="small"
      element-loading-text="查询中..."
      border
      fit
      highlight-current-row
    >

      <el-table-column align="center" width="80" label="日志Id" prop="id" />

      <el-table-column align="center" width="120" label="等级" prop="level">
        <template slot-scope="scope">
          <el-tag :type="levelColor(scope.row.level)">{{ scope.row.level | levelFilter }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column align="center" label="输出内容" min-width="150" prop="content" />

      <el-table-column align="center" width="200" label="创建时间" prop="gmtCreate">
        <template slot-scope="scope">{{ scope.row.gmtCreate | formatTime }}</template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <el-tooltip placement="top" content="返回顶部">
      <back-to-top :visibility-height="100" />
    </el-tooltip>
  </div>
</template>

<script>
import BackToTop from '@/components/BackToTop'
import Pagination from '@/components/Pagination'

const levelDic = { 0: '调试', 1: '信息', 2: '警告', 3: '错误' }
const levelColorDic = { 0: 'info', 1: 'primary', 2: 'warning', 3: 'danger' }
export default {
  name: 'DeviceLogList',
  components: { BackToTop, Pagination },
  filters: {
    levelFilter(code) {
      return levelDic[code]
    }
  },
  data() {
    return {
      // 常量
      // 变量
      listQuery: {
        page: 1,
        limit: 20,
        title: ''
      },
      total: 3,
      listLoading: false,
      list: [
        {
          id: 1,
          level: 1,
          content: '正常开机，室温26℃，外温101℃',
          gmtCreate: 1591598917738
        },
        {
          id: 1,
          level: 2,
          content: '正常开机，室温26℃，外温101℃',
          gmtCreate: 1591598917738
        },
        {
          id: 1,
          level: 3,
          content: '非正常关机，室温26℃，外温101℃',
          gmtCreate: 1591598917738
        }
      ]
    }
  },
  methods: {
    // 查询
    getList() {

    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    levelColor(code) {
      return levelColorDic[code]
    }
  }
}
</script>
